<template>
	<!-- 团购编辑 -->
	<view class="container">
		<uni-forms ref="baseForm" label-position="top" :modelValue="baseFormData">
			<!-- <uni-forms-item labelWidth="90px" class="form_item" label="商品分类" required name="ccate">
				<uni-data-select v-model="baseFormData.ccate" :localdata="typeList" :clear="false">
				</uni-data-select>
			</uni-forms-item> -->
			<uni-forms-item labelWidth="90px" label="团购名称" required name="title">
				<uni-easyinput v-model="baseFormData.title" placeholder="商品名称" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="团购原价(划线价)" required name="productprice">
				<uni-easyinput type="digit" @input="checkDecimalPoint($event,'productprice',3)" v-model="baseFormData.productprice" placeholder="最多2位小数点" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="团购售价(用户实际支付价格)" required name="saleprice">
				<uni-easyinput type="digit" @input="checkDecimalPoint($event,'saleprice',3)" @blur="setSaleprice" v-model="baseFormData.saleprice" placeholder="最多2位小数点" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="让利比例(3%-20%)" required name="sharerate">
				<!-- <text style="color: #8405dc;">建议设置5以上</text> -->
				<uni-number-box :min="3" :max="20" v-model="baseFormData.sharerate"  @change="setSaleprice" @blur="setSaleprice"></uni-number-box>
				<!-- <uni-easyinput type="number" @blur="setSaleprice" v-model="baseFormData.sharerate" placeholder="建议填写2-30" /> -->
					<!-- <uni-card :border="false" spacing="5px 0" padding="0" :is-shadow="false" is-full>
						<text class="message">  填写20，代表扣除20%，推广费越高，推广该商品的人数越多。该商品由物业公司、本地群主、商家客户群、宝妈团队长、兼职人员组成</text>
					</uni-card> -->
			</uni-forms-item>
			<view>
				<text>让利金额：</text>
				<text style="color: red;">-{{baseFormData.commisprice}}元</text>
			</view>
			<view>
				<text>顾客最高可获得：</text>
				<text style="color: red;">{{baseFormData.commisprice * 5}}元补贴（{{baseFormData.sharerate * 5}}%）</text>
			</view>
			<view>
				<text style="color: #666;">【提示】</text>
				<text style="color: #666;">该让利金额是发放给实际付款买家及买家上级团队的佣金奖励</text>
			</view>
			<uni-forms-item labelWidth="280px" label="商品结算价" required name="buyprice">
				<text>到店核销后，您可获得现金：</text>
				<text style="color: red;">{{baseFormData.buyprice}}元</text>
				<!-- <uni-easyinput disabled v-model="baseFormData.buyprice" placeholder="输入完推广比例,自动计算结算价" /> -->
			</uni-forms-item>
			<uni-card :border="false" spacing="5px 0" padding="0" :is-shadow="false" is-full>
				<text class="message">  团购核销后，收入进入[钱包余额]，提现无手续费。</text>
			</uni-card>
			<uni-forms-item labelWidth="250px" label="库存数量" required name="total">
				<uni-easyinput type="number" @input="checkDecimalPoint($event,'total',0)" v-model="baseFormData.total" placeholder="输入库存数量" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="每人限购数量(0为不限购)">
				<uni-easyinput type="number" @input="checkDecimalPoint($event,'limitnum',0)" v-model="baseFormData.limitnum" placeholder="输入限购数量" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="单次限购数量(0为不限购)">
				<uni-easyinput type="number" @input="checkDecimalPoint($event,'maxbuy',0)" v-model="baseFormData.maxbuy" placeholder="输入限购数量" />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="团购活动截止日期(到期停止售卖)" required>
				<view class="data_time"  @click="openPicker('timeend')">
					<text v-if="baseFormData.timeend">{{baseFormData.timeend}}</text>
					<text v-else>选择日期</text>
				</view>
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="顾客可消费日期(过期自动退款)" required>
				<uni-data-checkbox v-model="baseFormData.validday" :multiple="false" :localdata="range"></uni-data-checkbox>
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="兑换商品前,是否需要预约" required>
				<uni-data-checkbox v-model="baseFormData.isyy" :multiple="false" :localdata="isyyList"></uni-data-checkbox>
				<uni-data-checkbox v-show="baseFormData.isyy==1" v-model="baseFormData.yytype" :multiple="false" :localdata="yytypeList"></uni-data-checkbox>
				<view class="isyy" v-show="baseFormData.isyy==1&&baseFormData.yytype==0">
					<uni-data-select v-model="baseFormData.yytime" :localdata="yyhour"></uni-data-select>
				</view>
				<view class="isyy" v-show="baseFormData.isyy==1&&baseFormData.yytype==1">
					<uni-data-select v-model="baseFormData.yytime" :localdata="yyTime"></uni-data-select>
				</view>
			</uni-forms-item>
			<!-- <uni-forms-item labelWidth="90px" label="商品排序" name="displayorder">
				<uni-easyinput v-model="baseFormData.displayorder" placeholder="商品价格" />
			</uni-forms-item> -->
			<uni-forms-item labelWidth="250px" label="团购规则" required name="rule">
				<!-- <uni-easyinput type="textarea" v-model="baseFormData.rule" placeholder="可填写: 到店自提 / 需提前预约 / 周一到周日可用 " /> -->
				<uni-data-checkbox mode="list" :map="{text:'content',value:'id'}" v-model="buyRulesSelect" :multiple="true" :localdata="buyRules" @change="changeRule"></uni-data-checkbox>
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="其他说明信息">
				<uni-easyinput type="textarea" v-model="baseFormData.rule" placeholder="可填写其他团购规则 " />
			</uni-forms-item>
			<uni-forms-item labelWidth="250px" label="【团购商品搭配】">
				<view class="package">
					<view class="list" v-for="(item,idx) in baseFormData.markList" :key="uuidv4()">
						<view class="title">
							<text>团购组名称{{idx*1+1}}：</text>
							<button size="mini" @click="deleteLaber(idx)">删除{{idx*1+1}}组</button>
						</view>
						<uni-easyinput v-model="baseFormData.markList[idx].title" placeholder="输入分组名,如:超值双人餐/门票/火锅底料4选1" />
						<view class="content" v-for="(itm,i) in item.list" :key="uuidv4()">
							<view class="title2">
								<text>团购组包含的商品或项目{{idx*1+1}}：</text>
								<button size="mini" @click="deleteConent(idx,i)">删除</button>
							</view>
							<view class="cont">
								<uni-easyinput v-model="baseFormData.markList[idx].list[i].title" style="flex: 1;"
									placeholder="名称" />
								<uni-easyinput type="number" @input="checkDecimalPoint2($event,'markList',0,idx,i,'num')" v-model="baseFormData.markList[idx].list[i].num" style="flex: 1;"
									placeholder="数量" />
								<uni-easyinput type="digit" @input="checkDecimalPoint2($event,'markList',3,idx,i,'price')" v-model="baseFormData.markList[idx].list[i].price" style="flex: 1;"
									placeholder="原价" />
							</view>
						</view>
						<view class="" style="text-align: center;padding-top: 20upx;">
							<button size="mini" @click="addConent(idx)">添加团购内容</button>
						</view>
					</view>
					<view class="" style="text-align: center;">
						<button size="mini" style="width: 70%;" @click="addLaber">+添加商品组</button>
					</view>
					<view style="color: #f56c6c;font-size: 12px;" v-if="isMarkList">
						请正确填写团购详情
					</view>
				</view>
			</uni-forms-item>
			<uni-forms-item labelWidth="90px" class="form_item" label="商品头图" required name="thumb">
				<label for="" class="t_label">上传1张，建议选用高清优质图，提升客流</label>
					<view class="f_imgs">
						<view class="f_img" v-if="baseFormData.thumb.length>0">
							<image :src="baseFormData.thumb" @click="previewImg(0,baseFormData.thumb)"></image>
							<text @click="deleteImg(index,1)">×</text>
						</view>
						<view class="f_img" v-else @click="selectGallery(1)">
							<image class="reaname_thumb_upload" src="/static/shizi.jpg" ></image>
						</view>
					</view>
			</uni-forms-item>
			<uni-forms-item labelWidth="130px" class="form_item" label="商品轮播" required name="thumb_url">
				<label for="" class="t_label">建议2-4张，(约800*500像素比例)</label>
					<view class="f_imgs">
						<view class="f_img" v-for="(item,index) in baseFormData.thumb_url">
							<image :src="item" @click="previewImg(index,baseFormData.thumb_url)"></image>
							<text @click="deleteImg(index,2)">×</text>
						</view>
						<view class="f_img" @click="selectGallery(2)">
							<image class="reaname_thumb_upload" src="/static/shizi.jpg" ></image>
						</view>
					</view>
			</uni-forms-item>
			<uni-forms-item labelWidth="110px" class="form_item" label="商品视频" name="vodurl">
				<label for="" class="t_label">最多上传1个视频</label>
					<view class="f_imgs">
						<view class="f_img" v-if="baseFormData.vodurl&&baseFormData.vodurl!=''">
							<video :src="baseFormData.vodurl"></video>
							<text @click="deleteImg(index,4)">×</text>
						</view>
						<view class="f_img" v-else @click="selectGallery(4)">
							<image class="reaname_thumb_upload" src="/static/shizi.jpg" ></image>
						</view>
					</view>
				<!-- <uni-file-picker limit="1" file-mediatype="video" v-model="baseFormData.vodurl" @select="uploadVideo" title="最多上传1个视频"></uni-file-picker> -->
			</uni-forms-item>
			<uni-forms-item labelWidth="110px" class="form_item" label="环境(选填)" name="content">
				<label for="" class="t_label">良好的就餐环境也是用户的优先选择</label>
				<view class="f_imgs">
					<view class="f_img" v-for="(item,index) in baseFormData.content">
						<image :src="item" @click="previewImg(index,baseFormData.content)"></image>
						<text @click="deleteImg(index,3)">×</text>
					</view>
					<view class="f_img" @click="selectGallery(3)">
						<image class="reaname_thumb_upload" src="/static/shizi.jpg" ></image>
					</view>
				</view>
				<!-- <shmily-drag-image v-model="baseFormData.content" :addImage="uplaodThumb" :cols="3"></shmily-drag-image> -->
			</uni-forms-item>
			<block v-if="storeList&&storeList.length>0">
				<uni-forms-item labelWidth="250px" label="选择同步上架门店" name="shop">
					<uni-data-checkbox mode="list" :map="{text:'supname',value:'uid'}" v-model="baseFormData.uids" :multiple="true" :localdata="storeList" @change="changeShop"></uni-data-checkbox>
				</uni-forms-item>
			</block>
			<view class="buttons">
				<button v-if="id!=-1" class="go_submit" type="primary" style="background-color: red;"
					@click="deleteShop">删除</button>
				<button class="go_submit" type="primary" @click="submit('baseForm')">提交</button>
<!-- 				<button v-if="id!=-1" class="go_submit" type="primary" style="background-color: #4399fc;"
					@click="down">下架</button>s
				<button v-if="id!=-1" class="go_submit" type="primary" style="background-color: #f0ad4e;"
					@click="goodsUp">上架</button> -->
			</view>
		</uni-forms>
		<simple-datetime-picker ref="myPicker" :startYear="2023" :isd="true" @submit="handleSubmit"></simple-datetime-picker>
		<view class="fill" v-show="isShow">
			<view class="fill_item">
				<!-- #ifdef MP-ALIPAY -->
				<l-clipper v-if="isShow" :width="curWidth" :height="curHeight" :is-show-photo-btn="false" :image-url="imageSrc" @success="crop" @cancel="cancelCrop"  />
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<bt-cropper ref="cropper" :ratio="ratio" :imageSrc="imageSrc"></bt-cropper>
				<button @click="crop">确定</button>
				<button @click="cancelCrop" style="margin-top:30rpx">重新选择图片</button>
				<!-- #endif -->
			</view>
		</view>
		<uni-drawer ref="showRight" mode="left" :width="320" :mask-click="false">
			<gallery-list @changeImg="changeImg" :isMultiple="isMultiple" @getGalleryList="getGalleryList" :list="gallerylist" :uid="uid" :type="selectType"></gallery-list>
		</uni-drawer>
	</view>
</template>
<script>
	let token = uni.getStorageSync('token') ? uni.getStorageSync('token') : '';
	import SimpleDateTimePicker from '@/components/simple-datetime-picker/simple-datetime-picker.vue'
	import galleryList from '@/components/galleryList.vue'
	import {
		v4 as uuidv4
	} from 'uuid'
	import {
		mapState
	} from 'vuex'
	export default {
		components: {              //时间组件
			SimpleDateTimePicker,galleryList
		},
		computed: {
			...mapState(["url"])
		},
		data() {
			return {
				// page: 0,
				// isloading: false,
				// ismore: false,
				// gallerylist: [],
				isCut: false,//是否裁剪
				showGallery: false,//是否显示图库
				isMultiple: false,//是否多选 
				isShow: false,
				ratio: 16/9,
				curWidth: 800,
				curHeight: 500,
				selectType:0,
				imageSrc: '',
				range: [{"value": '7',"text": "7天"	},{"value": '15',"text": "15天"},{"value": '30',"text": "一个月"},{"value": '90',"text": "三个月"},{"value": '180',"text": "六个月"},{"value": '365',"text": "一年"}],
				buyRules: [],
				buyRulesSelect: ["1","2","3","4","7","8"],
				id: -1,
				uid: '',
				setDataTime: '',
				storeList: [],//门店列表
				isyyList: [{'value':"0","text":"不需要"},{"value":"1","text":"需要预约"}],
				yytypeList: [{'value':"0","text":"按小时预约"},{"value":"1","text":"按时间点预约"}],
				yyhour: [
					{'value':'0.5','text':'0.5小时'},
					{'value':'1','text':'1小时'},
					{'value':'2','text':'2小时'},
					{'value':'3','text':'3小时'},
					{'value':'4','text':'4小时'},
					{'value':'5','text':'5小时'},
					{'value':'6','text':'6小时'},
					{'value':'7','text':'7小时'},
					{'value':'8','text':'8小时'},
					{'value':'9','text':'9小时'},
					{'value':'10','text':'10小时'},
					{'value':'11','text':'11小时'},
					{'value':'12','text':'12小时'},
					{'value':'13','text':'13小时'},
					{'value':'14','text':'14小时'},
					{'value':'15','text':'15小时'},
					{'value':'16','text':'16小时'},
					{'value':'17','text':'17小时'},
					{'value':'18','text':'18小时'},
					{'value':'19','text':'19小时'},
					{'value':'20','text':'20小时'},
					{'value':'21','text':'21小时'},
					{'value':'22','text':'22小时'},
					{'value':'23','text':'23小时'},
					{'value':'24','text':'24小时'},
				],
				yyTime: [
					{'value':'6','text':'当日06:00前'},
					{'value':'7','text':'当日07:00前'},
					{'value':'8','text':'当日08:00前'},
					{'value':'9','text':'当日09:00前'},
					{'value':'10','text':'当日10:00前'},
					{'value':'11','text':'当日11:00前'},
					{'value':'12','text':'当日12:00前'},
					{'value':'13','text':'当日13:00前'},
					{'value':'14','text':'当日14:00前'},
					{'value':'15','text':'当日15:00前'},
					{'value':'16','text':'当日16:00前'},
					{'value':'17','text':'当日17:00前'},
					{'value':'18','text':'当日18:00前'},
					{'value':'19','text':'当日19:00前'},
					{'value':'20','text':'当日20:00前'},
					{'value':'21','text':'当日21:00前'},
					{'value':'22','text':'当日22:00前'},
					{'value':'23','text':'当日23:00前'},
					{'value':'23','text':'当日23:30前'},
				],
				baseFormData: {
					// ccate: '', //商品分类
					title: '', //标题
					productprice: '', //原价
					buyprice: '', //结算价
					saleprice: '', //售价
					commisprice: '0', //让利金额
					total: 1000, //库存
					markList: [], //团购套餐
					rule: '', //团购规则
					thumb: {}, //商品图
					thumb_url: [], //商品轮播图,
					vodurl: [],//视频
					content: [], //商品详情图
					limitnum: 0,//每人限购数量
					maxbuy: 0,//单次限购数量
					sharerate: 3,
					timeend: '2026-12-31',
					validday: "365",
					grouprule: '',
					isyy: "0",//是否需要预约 0不需要 1需要
					yytype: "0",//0按小时预约 1按时间点预约
					yytime: '',//几点之前或者几小时,
					uids: []
				},
				// typeList: [],
				isMarkList: false,
				rules: {
					// ccate: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请选择分类',
					// 	}]
					// },
					title: {
						rules: [{
							required: true,
							errorMessage: '请填写商品名',
						}]
					},
					productprice: {
						rules: [{
							required: true,
							errorMessage: '请填写原价',
						}]
					},
					sharerate: {
						rules: [{
							required: true,
							errorMessage: '请填写推广比例',
						}]
					},
					buyprice: {
						rules: [{
							required: true,
							errorMessage: '请填写结算价',
						}]
					},
					total: {
						rules: [{
							required: true,
							errorMessage: '请填写库存',
						}]
					},
					// rule: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请填写团购规则',
					// 	}]
					// },
					thumb: {
						rules: [{
							required: true,
							errorMessage: '请选择商品图片',
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.url === '') return false;
							}
						}]
					},
					thumb_url: {
						rules: [{
							required: true,
							errorMessage: '请选择商品轮播图',
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.length <= 0) return false;
							}
						}]
					},
					// content: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请选择商品详情图',
					// 	}, {
					// 		validateFunction: function(rule, value, data, callback) {
					// 			if (value.length <= 0) return false;
					// 		}
					// 	}]
					// },

				}
			}
		},
		onReady() {
			this.$refs.baseForm.setRules(this.rules)
		},
		onLoad(option) {
			this.id = option.id ? option.id : this.id;
			this.uid = option.uid;
			console.log(this.uid)
			if (this.id != -1) this.getInfo();
			this.getRules();
			this.getStore();
			// this.getGalleryList();
		},
		methods: {
			// 获取图库图片
			// getGalleryList(){
			// 	this.page++;
			// 	this.isloading = true;
			// 	this.ismore = false;
			// 	this.$axios('picwarehouse/lists','POST','supplier',{
			// 		page: this.page,
			// 	    uid: this.uid,
			// 		type: this.type
			// 	}).then(res=>{
			// 		uni.hideLoading();
			// 		if(res.data.code == 200){
			// 			this.isloading = false;
			// 			this.gallerylist = [...this.gallerylist,...res.data.data];
			// 			this.ismore = res.data.data.length <= 0;
			// 		}
			// 	})
			// },
			// 获取集团门店列表
			getStore(){
				this.$axios('groupgoods/groupSupList','POST','supplier',{
					uid: this.uid
				}).then(res=>{
					if(res.data.code == 200){
						this.storeList = res.data.data.list;
					}
				})
			},
			// 选择图片弹窗
			selectGallery(type){
				this.isCut = type;
				if(type==4){
					this.selectType = 1;
				}else{
					this.selectType = 0;
				}
				if(type==3){
					this.isMultiple = true;
				}else{
					this.isMultiple = false;
					if(type==1){
						this.ratio = 1/1;
						this.curHeight = 800;
					}else{
						this.ratio = 16/9;
						this.curHeight = 500;
					}
				}
				if(type==4){
					uni.showActionSheet({
						itemList: ['上传视频', '门店图库'],
						success: res=> {
							if(res.tapIndex == 0){//上传图片
								this.uploadVideo(type,1)// 单选
							}else if(res.tapIndex == 1){//门店图库
								this.$refs['showRight'].open()
							}
						},
					});
				}else{
					uni.showActionSheet({
						itemList: ['上传图片', '门店图库'],
						success: res=> {
							if(res.tapIndex == 0){//上传图片
								if(type==3){
									this.uplaodThumb(type,9)// 多选
								}else{
									this.uplaodThumb(type,1)// 单选
								}
							}else if(res.tapIndex == 1){//门店图库
								this.$refs['showRight'].open()
							}
						},
					});
				}
			},
			// 裁剪弹框
			showCut(url){
				let that = this;
				that.imageSrc = url;
				that.isShow = true;
			},
			// 裁剪确认
			crop(e){
				// #ifdef MP-WEIXIN
			    // 通过组件定义的ref调用cropper方法，返回一个promise对象
			    this.$refs.cropper.crop().then((res)=>{
					this.realUpload(res,this.isCut);
			    })
				// #endif
				// #ifdef MP-ALIPAY
				console.log(e)
				this.realUpload(e.url,this.isCut);
				// #endif
			},
			cancelCrop(){
				this.imageSrc = "";
				this.isShow = false;
			},
			// 图库选择图片
			changeImg(arr, type){
				this.$refs['showRight'].close()
				if(arr.length>0){
					if(this.isCut==2||this.isCut==1){
						this.showCut(arr);
					}else{
						if(this.isMultiple){
							this.baseFormData.content = [...this.baseFormData.content,...arr];
						}
					}
					if(this.isCut==4){
						this.baseFormData.vodurl = arr;
					}
				}
			},
			// 选择图片
			uplaodThumb(type,count) {
				uni.chooseImage({
					count: count,
					success:res=>{
						var path = res.tempFilePaths;
						path.forEach((image)=>{
							if(type==3){
								this.realUpload(image,type);
							}else{
								this.showCut(image);
							}
						})
					}
				})
			},
			// 上传服务器
			realUpload(image,type){
				var that = this;
				let arr = '';
				uni.showLoading({
					title: '上传中,请稍后'
				});
				uni.uploadFile({
					url: that.$url.state.url.upload,
					filePath: image,
					name: 'a',
					header: {
						token: token
					},
					formData: {
						'file': 'a'
					},
					success: upres => {
						let data = JSON.parse(upres.data);
						if (data.code == 200) {
							arr = data.data.url;
							if (type == 1) that.baseFormData.thumb = arr;
							if (type == 2) that.baseFormData.thumb_url.push(arr);
							if (type == 3) that.baseFormData.content.push(arr);;
							uni.hideLoading();
							that.isShow = false;
						}
					},
					fail() {
						setTimeout(() => {
							that.$api.msg('上传失败，请重试')
						}, 100)
					},
				})
			},
			// 预览图片
			previewImg(idx,arr){
				if(typeof arr === 'string'){
					let arrs = [];
					arrs.push(arr);
					arr = arrs;
				}
				uni.previewImage({
					current: idx,
					urls: arr
				})
			},
			// 删除图片
			deleteImg(e, type) {
				if (type == 1) this.baseFormData.thumb = {};
				if (type == 2) this.baseFormData.thumb_url.splice(e, 1);
				if (type == 3) this.baseFormData.content.splice(e, 1);
				if (type == 4) this.baseFormData.vodurl = '';
			},
			uploadVideo(e){
				var that = this;
				uni.showLoading({
					title: '上传中,请稍后'
				});
				uni.chooseVideo({
					count: 1,
					success:res=>{
						var path = res.tempFilePath;
						uni.uploadFile({
							url: that.$url.state.url.uploadvod,
							filePath: path,
							name: 'a',
							header: {
								token: uni.getStorageSync('token')
							},
							formData: {
								'file': 'a'
							},
							success: upres => {
								let data = JSON.parse(upres.data);
								if (data.code == 200) {
									that.baseFormData.vodurl = data.data.url;
								} else {
									that.$api.msg(upres.data.data)
								}
							},
							fail() {
								setTimeout(() => {
									that.$api.msg('上传失败，请重试')
								}, 100)
							},
							complete() {
								uni.hideLoading();
							}
						})
					},
					complete() {
						uni.hideLoading();
					}
				})
			},
			// 提交
			submit(ref) {
				let value = this.baseFormData.markList;
				// if (value.length <= 0) {
				// 	this.isMarkList = true;
				// 	return
				// }
				console.log(value);
				// return;
				if(value.length>0){
					let arr = value.map(v => {
						let arr = v.list.map(v2 => {
							return v2.title !== '' && v2.num !== '' !== '' && v2
								.price !== '';
						})
						return v.title !== '' && arr.length > 0 && (!arr.includes(false));
					})
					if(arr.includes(false)){
						return this.$api.msg('请补充团购内容！');
					}
					// this.isMarkList = arr.includes(false);
				}
				// return;
				// if (this.isMarkList) return;
				if(Number(this.baseFormData.saleprice)>Number(this.baseFormData.productprice)) return this.$api.msg('售价不可高于原价');
				this.$refs[ref].validate().then(res => {
					if(this.baseFormData.isyy==0){
						this.baseFormData.yytype = 0;
						this.baseFormData.yytime = 0;
					}
					this.baseFormData.grouprule = this.buyRulesSelect.join(",");
					this.baseFormData.uids = this.baseFormData.uids.join(",");
					// console.log(this.baseFormData.vodurl);
					// return;
					// this.baseFormData.vodurl = this.baseFormData.vodurl.url || '';
					let obj = {
						...this.baseFormData,
						thumb: this.baseFormData.thumb,
						thumbs: this.baseFormData.thumb_url,
						content: this.baseFormData.content,
						marks: JSON.stringify(this.baseFormData.markList),
						uid: this.uid
					}
					uni.showLoading();
					// console.log(obj);return;
					this.$axios('groupgoods/goodsSave', "POST", 'supplier', obj).then(res => {
						if (res.data.code == 200) {
							uni.hideLoading();
							this.$api.msg('提交成功！');
							setTimeout(() => {
								this.$navBack();
							}, 500)
						}else{
							uni.hideLoading();
							this.$api.msg('提交失败！');
						}
					})
				}).catch(err => {
					console.log('err', err);
				})
			},
			// 获取信息
			getInfo() {
				this.$axios('groupgoods/goodsInfo', "POST", 'supplier', {
					id: this.id,
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						let data = res.data.data;
						if(!data.content||data.content[0]===''){
							data.content = [];
						}
						if(!data.thumb_url){
							data.thumb_url = [];
						}
						// if(!data.vodurl||data.vodurl==''){
						// 	data.vodurl = [];
						// }else{
						// 	data.vodurl = {
						// 		"name":data.vodurl,
						// 		"extname":"mp4",
						// 		"url":data.vodurl,
						// 	}
						// }
						this.buyRulesSelect = data.grouprule;
						this.baseFormData = data;
						this.baseFormData.commisprice = (this.baseFormData.saleprice - this.baseFormData.buyprice).toFixed(4);
					}
				})
			},
			// 团购规则
			getRules(){
				this.$axios('groupgoods/rulesList','POST','supplier').then(res=>{
					if(res.data.code == 200){
						this.buyRules = res.data.data.list;
					}
				})
			},
			changeRule(e){
				// console.log(e)
			},
			changeShop(e){
				// console.log(e)
			},
			 //保留小数点后2位 number取整填0 小数点保留2位，就填3，每次加1
			checkDecimalPoint(value,el,number){
				let newNum = '';
				newNum =  value.includes('.') ? value.substring(0, value.indexOf('.') + number) : value;
				this.$nextTick(()=>{
					this.baseFormData[el] = newNum
				})
			},
			//保留小数点后2位 number取整填0 小数点保留2位，就填3，每次加1
			checkDecimalPoint2(value,el,number,idx,i,name){
				let newNum = '';
				newNum =  value.includes('.') ? value.substring(0, value.indexOf('.') + number) : value;
				this.$nextTick(()=>{
					this.baseFormData[el][idx].list[i][name] = newNum
				})
			},
			// 日期选择
			handleSubmit(e) {
				if (!this.setDataTime) return;
				this.baseFormData[this.setDataTime] = `${e.year}-${e.month}-${e.day}`;
			},
			openPicker(v) {
				this.setDataTime = v;
				this.$refs.myPicker.show();
			},
			// 计算价格
			setSaleprice() {
				if (this.baseFormData.saleprice === '' || this.baseFormData.sharerate === '') return;
				this.baseFormData.buyprice = (this.baseFormData.saleprice * (100 - this.baseFormData.sharerate) / 100)
					.toFixed(4);
				this.baseFormData.commisprice = (this.baseFormData.saleprice-this.baseFormData.buyprice).toFixed(4);
			},
			uuidv4() {
				return uuidv4();
			},
			// 删除
			deleteShop() {
				uni.showModal({
					title: '提示',
					content: '是否确认删除？',
					success: res=> {
						if (res.confirm) {
							this.$axios('groupgoods/goodsDel', 'POST', 'supplier', {
								id: this.id,
								uid: this.uid
							}).then(res => {
								if (res.data.code == 200) {
									this.$api.msg(res.data.data);
									setTimeout(() => {
										this.$navBack();
									}, 500)
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			// 下架
			down() {
				this.$axios('groupgoods/goodsDown', 'POST', 'supplier', {
					id: this.id,
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.$api.msg("下架成功");
					}
				})
			},
			// 上架
			goodsUp() {
				this.$axios('groupgoods/goodsUp', 'POST', 'supplier', {
					id: this.id,
					uid: this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.$api.msg("上架成功!");
					}
				})
			},
			deleteConent(v, v2) {
				this.baseFormData.markList[v].list.splice(v2, 1);
			},
			deleteLaber(v) {
				this.baseFormData.markList.splice(v, 1);
			},
			addConent(idx) {
				this.baseFormData.markList[idx].list.push({
					title: '',
					num: '1',
					price: ''
				});
			},
			addLaber() {
				this.baseFormData.markList.push({
					title: '',
					list: []
				});
			},
		}
	}
</script>


<style lang="scss">
	.fill{
		width: 100%;
		height: 100%;
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(#000,.8);
		z-index: 999999;
		display: flex;
		align-items: center;
		justify-content: center;
		.fill_item{
			width: 800rpx;
			height: 500rpx;
		}
	}
	.container {
		padding-bottom: 100upx;
	}

	.uni-forms {
		padding: 0 20upx;
	}
	.t_label{
		color: #888;
		font-size: 24rpx;
		float: left;
		margin-top: -60rpx;
		margin-left: 150rpx;
	}
	.f_imgs{
		display: flex;
		flex-wrap: wrap;
		margin-right: -10rpx;
		.f_img{
			width: 220rpx;
			height: 220rpx;
			position: relative;
			margin: 20rpx 10rpx 0 0;
			image {
				height: 100%;
				width: 100%;
			}
			video{
				height: 100%;
				width: 100%;
			}
			text{
				background: #999;
				border-radius: 50%;
				color: #fff;
				height: 50upx;
				line-height: 40upx;
				font-size: 40upx;
				position: absolute;
				top: -10upx;
				right: -10upx;
				text-align: center;
				width: 50upx;
				opacity: .8;
			}
		}
	}
	
	.uni-forms .uni-forms-item {
		margin-top: 50upx;
		margin-bottom: 0;
	}

	.message {
		color: #999;
		font-size: 22upx;
	}

	.buttons {
		margin-top: 70upx;
		display: flex;
		align-items: center;

		.go_submit {
			flex: 1;
			line-height: 80upx;
			margin-right: 20upx;
			box-shadow: 4rpx 5rpx 17rpx 7rpx #ddd;
		}

		.go_submit:last-child {
			margin: 0;
		}

	}
	.data_time {
		border: 1px solid #e5e5e5;
		border-radius: 4px;
		color: #666;
		font-size: 14px;
		height: 35px;
		line-height: 35px;
		padding: 0 10px;
	}


	.position {
		border: 1px #e5e5e5 solid;
		border-radius: 4px;
		color: #999;
		line-height: 35px;
		font-size: 12px;
		padding: 0 20upx;
	}

	.package {
		.list {
			padding-bottom: 20upx;

			.title,
			.title2 {
				display: flex;
				align-items: center;
				padding-bottom: 20upx;
				button{
					background: red;
					color: #fff;
				}
			}
			
			.title2 {
				padding: 10upx 0;
			}

			.content {
				padding-left: 40upx;
			}

			.cont {
				display: flex;
				align-items: center;
			}
		}
	}
</style>